//
//  starView.m
//  movie
//
//  Created by 李丹阳 on 15/7/21.
//  Copyright (c) 2015年 李丹阳. All rights reserved.
//

//写在starView.m文件里

#import "starView.h"

@implementation starView



- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self _createSubview];
    }
    return self;
}

- (void)_createSubview{
    UIImage* yellowStar = [UIImage imageNamed:@"yellow"];
    UIImage* grayStar = [UIImage imageNamed:@"gray@2x"];
    
    yellowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,yellowStar.size.width*5 , yellowStar.size.height)];
    grayView  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, yellowStar.size.width*5, yellowStar.size.height)];
    
    yellowView.backgroundColor = [UIColor colorWithPatternImage:yellowStar];
    grayView .backgroundColor = [UIColor colorWithPatternImage:grayStar];
    
    
    //把视图放大
    float scale = self.frame.size.height/yellowStar.size.height;//求出放大倍数
    grayView.transform = CGAffineTransformMakeScale(scale, scale);
    yellowView.transform = CGAffineTransformMakeScale(scale, scale);//根据中心点放大
    
    //放大后，x, y的位置会改变，应该改成(0,0);
    CGRect frame = grayView.frame;
    frame.origin = CGPointZero;
    yellowView.frame = frame;
    
    [self addSubview:grayView];
    [self addSubview:yellowView];

}

- (void)setAverage:(float)average{
    _average = average;
    [self setNeedsLayout ];
}

- (void)layoutSubviews{
    float awidth = _average/10.0*grayView.frame.size.width;
    CGRect frame = grayView.frame;
    frame.size.width = awidth;
    yellowView.frame = frame;
    
//    [self addSubview:yellowView];

}

@end
